package cn.snowheart.singleton;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.IntStream;

/**
 * @author liuwanxiang
 * @version 2019/07/02
 */
public class SingletonTest {

    public static void main(String[] args) throws Exception {

        ExecutorService threadPool = Executors.newFixedThreadPool(2);
        CountDownLatch latch = new CountDownLatch(2);

        IntStream.range(0, 2).forEach(
                value -> threadPool.submit(() -> {
                    SingletonV1 singletonV1 = SingletonV1.getInstance();
                    System.out.println(singletonV1);

                    SingletonV2 singletonV2 = SingletonV2.getInstance();
                    System.out.println(singletonV2);

                    SingletonV3 singletonV3 = SingletonV3.getInstance();
                    System.out.println(singletonV3);

                    SingletonV4 singletonV4 = SingletonV4.getInstance();
                    System.out.println(singletonV4);

//                    Singleton singleton = Singleton.getInstance();
//                    System.out.println(singleton);

//                    IntStream.range(0, 100).forEach(i -> singletonV4.increase());

                    latch.countDown();
                })
        );
        latch.await();
        System.exit(0);

    }

}
